package com.luoqiz.design.singleton.type2;

public class SingletonTest02 {
    public static void main(String[] args) {

        Singleton singleton1 = Singleton.getInstance();
        Singleton singleton2 = Singleton.getInstance();

        System.out.println("singleton1 hashcode:" + singleton1.hashCode());
        System.out.println("singleton2 hashcode:" + singleton2.hashCode());
    }
}

//饿汉式 静态代码块实现
class Singleton {

    private static final Singleton singleton;

    static {
        singleton = new Singleton();
    }

    public static Singleton getInstance() {

        return singleton;
    }

}